package com.yuanchu.store.controller;

import com.yuanchu.common.utils.PageResult;
import com.yuanchu.common.utils.R;
import com.yuanchu.common.validator.ValidationGroups;
import com.yuanchu.store.dto.DeliveryParamsDto;
import com.yuanchu.store.entity.YoshopDeliveryEntity;
import com.yuanchu.store.entity.YoshopDeliveryRuleEntity;
import com.yuanchu.store.service.YoshopDeliveryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 配送模板主表
 *
 * @author adan
 * @email 2028038953@gmail.com
 * @date 2023-12-19 20:57:23
 */
@Api(tags = "配送模板主表接口 管理", description = "配送模板主表接口 管理")
@RestController
@RequestMapping("delivery")
public class StoreDeliveryController {

    @Resource
    private YoshopDeliveryService yoshopDeliveryService;

    /**
     * 配送列表
     */
    @ApiOperation("配送信息查询接口")
    @GetMapping("/all")
    public R list(@RequestParam(required = false) Map<String, Object> params) {
        List<YoshopDeliveryEntity> list = yoshopDeliveryService.queryGoodsDelivery(params);
        return R.ok().put("data", list);
    }

    /**
     * 配送列表
     */
    @ApiOperation("根据id查询配送信息")
    @GetMapping("/{deliveryId}")
    public YoshopDeliveryRuleEntity queryDeliveryBigDecimalById(@PathVariable("deliveryId") Integer deliveryId) {
        return yoshopDeliveryService.queryDeliveryBigDecimalById(deliveryId);
    }

    @ApiOperation("配送信息查询接口")
    @GetMapping("/list")
    public R deliveryList(@RequestParam("page") Integer page, @RequestParam(value = "search", required = false) String search) {
        PageResult<YoshopDeliveryEntity> list = yoshopDeliveryService.queryDeliveryList(page, search);
        return R.ok().putPage("data", list);
    }

    @ApiOperation("添加配送模板")
    @PostMapping("add")
    public R saveDelivery(@RequestBody DeliveryParamsDto params) {
        yoshopDeliveryService.saveDelivery(params);
        return R.ok();
    }

    @ApiOperation("修改配送模板")
    @PostMapping("edit")
    public R updateDelivery(@RequestBody @Validated(ValidationGroups.Update.class) DeliveryParamsDto params) {
        yoshopDeliveryService.updateDelivery(params);
        return R.ok();
    }
    @ApiOperation("删除配送模板")
    @PostMapping("delete")
    public R deleteDelivery(@RequestBody @Validated(ValidationGroups.Delete.class) DeliveryParamsDto params) {
        yoshopDeliveryService.deleteDelivery(params.getDeliveryId());
        return R.ok();
    }

    @ApiOperation("查询物流详情接口")
    @GetMapping("/detail")
    public R queryExpressDetail(@RequestParam("deliveryId") Integer deliveryId) {
        YoshopDeliveryEntity detail = yoshopDeliveryService.queryExpressDetail(deliveryId);
        Map<String, Object> map = new HashMap<>();
        map.put("detail", detail);
        return R.ok().put("data", map);
    }



}
